<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>我的地址</title>
  <meta name="renderer" content="webkit"/>
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
  {foreach name="list" item="v"}
      <div>
          姓名：<span>{$v.consignee}</span>
          电话：<span>{$v.mobile}</span>
          详细地址：<span>{$v.address}</span>
          <a href="{:url('User/add_edit_address')}?id={$v.id}">编辑</a>
          {if condition="$v.is_default eq 1"}
              <a href="javascript:;" onclick="cancel_default({$v.id})">取消默认</a>
          {else /}
              <a href="javascript:;" onclick="set_default({$v.id})">设置默认</a>
          {/if}
      </div>
  {/foreach}
  <br/>
  <a href="{:url('User/add_edit_address')}">添加</a>
</body>
</html>
<script>
    /**
     *  设置默认地址
     */
    function set_default(id){
        $.post("{:url('User/set_address_default')}",
            {id:id},
            function(data){
                if(data.code == 1){
                      alert('设置成功');
                      location.reload();
                }else{
                      alert('设置失败');
                }
            }
        );
    }

    /**
     *  取消默认地址
     */
    function cancel_default(id){
        $.post("{:url('User/cancel_address_default')}",
            {id:id},
            function(data){
                if(data.code == 1){
                    alert('取消成功');
                    location.reload();
                }else{
                    alert('取消失败');
                }
            }
        );
    }



</script>